package com.woniuxy.secondhand.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.life.core.api.CommonResult;
import com.woniuxy.secondhand.entity.SecGoodstype;
import com.woniuxy.secondhand.mapper.SecGoodstypeMapper;
import com.woniuxy.secondhand.service.SecGoodstypeService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 商品类型 前端控制器
 * </p>
 *
 * @author chaohuijiang
 * @since 2020-09-24
 */
@RestController
@RequestMapping("/secondhand/sec-goodstype")
public class SecGoodstypeController {
    @Resource
    SecGoodstypeMapper secGoodstypeMapper;
    @Resource
    SecGoodstypeService secGoodstypeService;
    //添加类型 后台管理员添加用户用不着
    @RequestMapping("/insert")
    public CommonResult<SecGoodstype> insertGoodsType(@RequestBody SecGoodstype secGoodstype){
        System.out.println(secGoodstype);
        secGoodstypeMapper.insert(secGoodstype);
        return CommonResult.success(secGoodstype);
    }
   //查询各种类型
    @RequestMapping("/findall")
    public ModelAndView findAll(){
        ModelAndView mv =new ModelAndView();
        QueryWrapper<SecGoodstype> queryWrapper=new QueryWrapper<>();
        List<SecGoodstype> secGoodstypes= secGoodstypeService.list(queryWrapper);
        System.out.println(secGoodstypes);
        mv.addObject("secGoodstypes",secGoodstypes);
        mv.setViewName("goodstype");
        return  mv;
    }
    //通过id查询单个类型信息
    @RequestMapping("/findone/{secGoodstypeId}")
   public CommonResult<SecGoodstype> findOne(@PathVariable("secGoodstypeId") Integer secGoodstypeId){
        SecGoodstype secGoodstype=secGoodstypeService.getById(secGoodstypeId);
        return CommonResult.success(secGoodstype);
   }
    //删除相关类型
    @DeleteMapping("/delete/{secGoodstypeId}")
    public CommonResult<SecGoodstype> deleteType(@PathVariable("secGoodstypeId") Integer secGoodstypeId){
        secGoodstypeMapper.deleteById(secGoodstypeId);
        return CommonResult.success();
    }
}
